package xyz.chaobei.date;

import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.time.temporal.ChronoUnit;

/**
 * @author <a href='mailto:maruichao52@gmail.com'>MRC</a>
 * @since 2021/2/19
 */
public class LocalTimeTest {

    public static void main(String[] args) {

        // 表示时间
        LocalTime time = LocalTime.now();
        System.out.println("1: 当前时间=" + time.toString());

        LocalTime american = LocalTime.now(ZoneId.of("America/Manaus"));
        System.out.println("2: America/Manaus 指定时区=" + american.toString());

        // 计算时间差值
        long offsetHours = ChronoUnit.HOURS.between(time, american);
        System.out.println(offsetHours);

        long offsetMinutes = ChronoUnit.MINUTES.between(time, american);
        System.out.println(offsetMinutes);

        System.out.println("--------------------------------");

        // 获得特定时间
        LocalTime custom = LocalTime.of(23, 59, 59);
        System.out.println("3: 手动指定时间=" + custom);

        // 时间格式化
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);

        String customFormat = custom.format(dateTimeFormatter);
        System.out.println("4: 使用格式化时间=" + customFormat);
    }

}
